package cn.xingzhe.monster.user.infrastructure.persistence.converter;

import cn.xingzhe.monster.user.domain.model.CaptchaModel;
import cn.xingzhe.monster.user.infrastructure.persistence.entity.CaptchaEntity;

/**
 * 验证码实体转换器
 * 负责 CaptchaEntity 和 CaptchaModel 之间的转换
 *
 * @author System
 * @version 1.0.0
 * @since 2024-01-01
 */
public class CaptchaEntityConverter {

    /**
     * Entity 转 Model
     *
     * @param entity 实体
     * @return 领域模型
     */
    public static CaptchaModel toModel(CaptchaEntity entity) {
        if (entity == null) {
            return null;
        }
        return CaptchaModel.builder()
                .id(entity.getId())
                .key(entity.getKey())
                .code(entity.getCode())
                .type(entity.getType())
                .expireTime(entity.getExpireTime())
                .createTime(entity.getCreateTime())
                .build();
    }

    /**
     * Model 转 Entity
     *
     * @param model 领域模型
     * @return 实体
     */
    public static CaptchaEntity toEntity(CaptchaModel model) {
        if (model == null) {
            return null;
        }
        return CaptchaEntity.builder()
                .id(model.getId())
                .key(model.getKey())
                .code(model.getCode())
                .type(model.getType())
                .expireTime(model.getExpireTime())
                .createTime(model.getCreateTime())
                .build();
    }
}

